package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcLabVisitEntity;
import com.dhcc.cdc.busi.service.ICdcLabVisitService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 标本送检记录
 * 
 * @ClassName: LabVisitController
 * @Description: TODO
 * @author jumper
 * @date 2021-04-26 16:21:40
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/labvisit")
public class CdcLabVisitController extends BaseController {

	private String PREFIX = "/backend/cdc/labvisit/";

	@Autowired
	private ICdcLabVisitService labVisitService;
	

    /**
     * 跳转到标本送检记录列表首页
     */
    @RequestMapping("")
    @Permission("labvisit:list")
    public String index() {
        return PREFIX + "labvisit.html";
    }
	
    /**
     * 跳转到新增标本送检记录
     */
    @RequestMapping("/to_add")
    @Permission("labvisit:add")
    public String toAdd() {
        return PREFIX + "labvisit_add.html";
    }
	
	/**
     * 跳转到修改标本送检记录
     */
    @RequestMapping("/to_update/{labVisitId}")
    @Permission("labvisit:update")
    public String toUpdate(@PathVariable Long labVisitId, Model model) {
        CdcLabVisitEntity labVisit = this.labVisitService.selectById(labVisitId);
        model.addAttribute("labVisit",labVisit);
        return PREFIX + "labvisit_edit.html";
    }

    /**
     * 获取标本送检记录列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("labvisit:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcLabVisitEntity> page = new PageFactory<CdcLabVisitEntity>().defaultPage();
        List<CdcLabVisitEntity> result = this.labVisitService.page(page,params);
        page.setRecords((List<CdcLabVisitEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增标本送检记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("labvisit:add")
    @BussinessLog(value = "新增标本送检记录")
    public Object add(CdcLabVisitEntity labVisit) {
        if (CommonUtil.isOneEmpty(labVisit)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        labVisit.insert();
        return R.ok();
    }

    /**
     * 删除标本送检记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("labvisit:delete")
    @BussinessLog(value = "删除标本送检记录")
    public Object delete(@RequestParam Long labVisitId) {
	
        this.labVisitService.deleteById(labVisitId);

        return R.ok();
    }

    /**
     * 修改标本送检记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("labvisit:update")
    @BussinessLog(value = "修改标本送检记录")
    public Object update(CdcLabVisitEntity labVisit) {
        if (CommonUtil.isOneEmpty(labVisit)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcLabVisitEntity old = this.labVisitService.selectById(labVisit.getId());

        old.setEpisodeId(labVisit.getEpisodeId());
        old.setXcode(labVisit.getXcode());
        old.setSpecVisitNum(labVisit.getSpecVisitNum());
        old.setSpecimen(labVisit.getSpecimen());
        old.setLabLocId(labVisit.getLabLocId());
        old.setLabWardId(labVisit.getLabWardId());
        old.setColDate(labVisit.getColDate());
        old.setColUserName(labVisit.getColUserName());
        old.setRecDate(labVisit.getRecDate());
        old.setRecUserName(labVisit.getRecUserName());
        old.setDataId(labVisit.getDataId());
        old.setIsActive(labVisit.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
